package com.hero.jobweb.config;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.apache.commons.lang.math.NumberUtils;


public abstract class MessagesManger {
	//加载系统用到的资源
	private static ResourceBundle exceptionRb=null;
	private static ResourceBundle systemRb=null;
	static
	{
		exceptionRb=ResourceBundle.getBundle(ExceptionKey.EXCEPTION_MESSAGE_BUNDLE.toString());
		systemRb=ResourceBundle.getBundle(SystemKey.SYSTEM_MESSAGE_BUNDLE.toString());
	}
	
	public static String getExceptionMessages(String key)
	{
	    return getString(exceptionRb, key);
	}
	public static String getExceptionMessages(String key,Object ...parm)
	{
	    return getString(exceptionRb, key,parm);
	}
	
	
	
	
	public static String getSystemMessages(String key)
	{
	    return getString(systemRb, key);
	}
	public static String getSystemMessages(String key,Object ...parm)
	{
	    return getString(systemRb, key,parm);
	}
	
	public static String getSystemMessages(SystemKey key)
	{
	    return getString(systemRb, key.toString());
	}
	public static String getSystemMessages(SystemKey key,Object ...parm)
	{
	    return getString(systemRb, key.toString(),parm);
	}
	
	
	public static Integer getSystemMessagesInt(SystemKey key)
	{
	    return getInt(systemRb, key.toString());
	}
	
	
	
	
	
	
	
	
	public static Integer getInt(ResourceBundle resourceBundle,String key) {
        try {
            return  NumberUtils.createInteger(resourceBundle.getString(key));
        } catch (MissingResourceException e) {
            return null;
        }
    }
	public static String getString(ResourceBundle resourceBundle,String key) {
        try {
            return resourceBundle.getString(key);
        } catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }
    public static String getString(ResourceBundle resourceBundle,String key, Object ...parm) {
        try {
            return MessageFormat.format(resourceBundle.getString(key),parm);
        } catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }
}
